package fr.esiag.isidis.epp.launcher;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import fr.esiag.isidis.epp.generatedClasses.Query;
import fr.esiag.isidis.epp.search.PointCdc;
import fr.esiag.isidis.epp.search.PointCdcRowMapperindividual;
import fr.esiag.isidis.epp.search.PointCdcService;
import fr.esiag.isidis.epp.service.CDCAndWeightService;
import fr.esiag.isidis.epp.service.SiteService;
import fr.esiag.isidis.epp.service.TemperatureService;

/**
 * 
 * @author MEDINI
 * @author christian
 *
 */
public class EPPLauncher 
{
	private static Logger logger = Logger.getLogger(EPPLauncher.class);
	
    public static void main( String[] args )
    {
    	String id;
		int dateDebut;
		int heureDebut;
		int dateFin;
		int heureFin;
		List<PointCdc> names;
		ApplicationContext context = new FileSystemXmlApplicationContext("classpath:/epp-context.xml");
       
    	DataSource dataSource = (DataSource) context.getBean("dataSource");
    	JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    	
    	Query q = new Query();
    	List<PointCdc> lpi;
    	List<PointCdc> lpc;
    	List<PointCdc> lpm;
    	q.setDateDebut(20110101);
    	q.setDateFin(20121212);
    	q.setHeureDebut(0);
    	q.setHeureFin(1200);
    	q.setIDSite("ID01");
    		
    	PointCdcService pt = context.getBean(PointCdcService.class);
    		lpi = pt.makeIndividuel(q);
    		lpc = pt.makeCumul(q);
        	lpm = pt.makeMoyenne(q);
    		
    		
   	System.out.println("************* INDIVIDUAL **************");
    	for (PointCdc p : lpi){
   		System.out.println("Date : " + p.getDateConso());
    		System.out.println("Heure : " + p.getHeureConso());
    		System.out.println("ID "+ p.getId());
   		System.out.println("TEMP "+ p.getTemperature());
   		System.out.println("Puissance "+p.getPuissance());
   		System.out.println("POIDS "+p.getPoids());
   	}
    	
    	System.out.println("************* Cumul **************");
        	for (PointCdc p : lpc){
       		System.out.println("Date : " + p.getDateConso());
        		System.out.println("Heure : " + p.getHeureConso());
        		System.out.println("ID "+ p.getId());
       		System.out.println("TEMP "+ p.getTemperature());
       		System.out.println("Puissance "+p.getPuissance());
       		System.out.println("POIDS "+p.getPoids());
       	}
        	
    	System.out.println("************* MOYENNE **************");
        	for (PointCdc p : lpm){
       		System.out.println("Date : " + p.getDateConso());
        		System.out.println("Heure : " + p.getHeureConso());
        		System.out.println("ID "+ p.getId());
       		System.out.println("TEMP "+ p.getTemperature());
       		System.out.println("Puissance "+p.getPuissance());
       		System.out.println("POIDS "+p.getPoids());
       	}
        	
    	/* CDCAndWeightService cdcWeightService = context.getBean(CDCAndWeightService.class);
		SiteService site = context.getBean(SiteService.class);
		TemperatureService temp = context.getBean(TemperatureService.class); */
//        try 
//		{
//			
//        	//site.loadCsvFile();
//        	logger.debug("FIN DE L'INSERTION DU SITE et de ACTIVITY");
//        	//cdcWeightService.loadCsvFile();
//			logger.debug("FIN DE L'INSERTION DE CDC et WEIGHT");
//			//temp.loadCsvFile();
//			logger.debug("FIN DE L'INSERTION DE TEMPERATURE");	
//			logger.debug("FIN DE L'INSERTION DES FICHIERS");
//		} catch (Exception e) {
//			e.printStackTrace();
//			logger.error("INSERTION NON ACHEVEE");
//		}
//		
		
    }
}
